﻿using IntermediateExam2DbAndXml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;

namespace TestPets
{
    
    
    [TestClass()]
    public class PetsTest
    {
        public static void CheckPets(SortedDictionary<string, SortedSet<string>> expected,
            SortedDictionary<string, SortedSet<string>> actual) 
        {
            Assert.AreEqual(actual.Count, expected.Count);
            foreach (var animal in expected)
            {
                Assert.IsTrue(actual.ContainsKey(animal.Key));
                foreach (var item in animal.Value)
                {
                    Assert.IsTrue(actual[animal.Key].Contains(item));
                }
                
            }
        }
       
        [TestMethod()]
        public void GetPetsTest()
        {
            string fileName = "../../../petsTest.xml";
            SortedDictionary<string, SortedSet<string>> expected = new SortedDictionary<string, SortedSet<string>>();
            expected.Add("Dog", new SortedSet<string>());
            expected["Dog"].Add("Pesho");
            SortedDictionary<string, SortedSet<string>> actual;
            actual = Pets.GetPets(fileName);
            CheckPets(expected, actual);
        }

        [TestMethod()]
        [ExpectedException(typeof(FileNotFoundException))]
        public void GetPetsTestWronFile()
        {
            string fileName = "../../../petsTest2.xml";
            SortedDictionary<string, SortedSet<string>> expected = new SortedDictionary<string, SortedSet<string>>();
            expected.Add("Dog", new SortedSet<string>());
            expected["Dog"].Add("Pesho");
            SortedDictionary<string, SortedSet<string>> actual;
            actual = Pets.GetPets(fileName);
            CheckPets(expected, actual);
        }

        [TestMethod()]
        [Timeout(500)]
        public void GetPetsTestBigFile()
        {
            string fileName = "../../../petsTestBig.xml";
            SortedDictionary<string, SortedSet<string>> actual;
            actual = Pets.GetPets(fileName);
        }

        [TestMethod()]
        public void ExportTodXmlTest()
        {
            SortedDictionary<string, SortedSet<string>> pets = null; // TODO: Initialize to an appropriate value
            string filename = string.Empty; // TODO: Initialize to an appropriate value
            Pets.ExportTodXml(pets, filename);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

    }
}
